Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach LastResponse after unmarshaling #1123

Merged
merged 1 commit into from
Jun 11, 2020
Merged

Conversation

bryan-stripe
Copy link
Contributor

If a resource has a custom UnmarshalJSON file like Charge does, we lose the LastResponse property of the APIResource due to ordering.

Additionally—there's a guard here which doesn't make much sense which I've removed. If v is ever nil here, we'd panic before hitting the guard.

I found it kind of awkward to write a test for this behavior—the existing test in stripe_test.go doesn't expose it because it has no custom UnmarshalJSON defined; if you look at the definition for Charge you can see it completely overwrites the object (as do several others).

r? @brandur-stripe
cc @stripe/api-libraries

Copy link
Contributor

@brandur-stripe brandur-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. And yeah, I think that check on v is probably just a code artifact from before some previous refactoring.

It might not be too bad to write a test for this by just creating a specific type with UnmarshalJSON for the purposes of the test, but it probably doesn't matter too much. I'd say that this isn't too likely to regress.

@remi-stripe remi-stripe merged commit bfa3225 into master Jun 11, 2020
@remi-stripe remi-stripe deleted the bryan-fix-lastresponse branch June 11, 2020 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants